﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Hospitals.Collection
{
    public partial class InvoiceList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                QueryResult();
            }

        }
        /// <summary>
        /// 数据绑定
        /// </summary>
        private void QueryResult()
        {
            IList<Model.View.InvoicePay> lstInvoicePay = new List<Model.View.InvoicePay>();
            Model.Query.InvoicePay qryCondition = new Model.Query.InvoicePay();

            if (Request.QueryString["ID"] != null)
            {
                qryCondition.InvoicePaySerialID = Request.QueryString["ID"].ToString();
            }
            else
            {
                User user = CurrentAccount.GetUser();
                qryCondition.CompanyID_PS = user.Org.OrgID;
            }
            qryCondition.SortFields = " InvoicePayTime desc ";
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            lstInvoicePay = iPurchase.GetInvoicePayByWhere(qryCondition, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwRefundDetail.DataSource = lstInvoicePay;
            gvwRefundDetail.DataBind();


            //绑定结算单基本信息
            lblActualAmount.Text = lstInvoicePay[0].ActualAmount.ToString();
            lblPayAmount.Text = lstInvoicePay[0].PayAmount.ToString();
            lblPayId.Text = lstInvoicePay[0].InvoicePayNo;
            lblPayName.Text = lstInvoicePay[0].InvoicePayName;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            QueryResult();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            QueryResult();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwRefundDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //0未确认;1已确认;
                Literal ltr = e.Row.FindControl("ltrStatus") as Literal;
                if (ltr.Text == "0")
                {
                    ltr.Text = "未确认";
                }
                else if (ltr.Text == "1")
                {
                    ltr.Text = "已确认";
                }

            }
        }
    }
}
